package com.lanchetech.admin.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Configuration
@EnableAsync
@Slf4j
public class ExecutorConfig {


    // 核心线程数
//    @Value("${async.executor.thread.core_pool_size}")
//    private int corePoolSize;
//    // 最大线程数
//    @Value("${async.executor.thread.max_pool_size}")
//    private int maxPoolSize;
//    // 队列大小
//    @Value("${async.executor.thread.queue_capacity}")
//    private int queueCapacity;
//    // 线程前缀名称
//    @Value("${async.executor.thread.name.prefix}")
//    private String namePrefix;

//    @Bean("asyncServiceExecutor")
//    public Executor asyncServiceExecutor() {
//        log.warn("start asyncServiceExecutor");
//        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//        executor.setCorePoolSize(corePoolSize);
//        executor.setMaxPoolSize(maxPoolSize);
//        executor.setQueueCapacity(queueCapacity);
//        executor.setThreadNamePrefix(namePrefix);
//        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
//        executor.initialize();
//        return executor;
//    }
}
